unit EnrollmentOptionsForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, NCore, NUtils, NBiometrics;

type
  TEnrollmentOptionsFrom = class(TForm)
    SearchForDuplicatesCheckBox: TCheckBox;
    MinimalMinutiaCountCheckBox: TCheckBox;
    UseQualityCheckBox: TCheckBox;
    ThresholdLabel: TLabel;
    ModeLabel: TLabel;
    ModeComboBox: TComboBox;
    TemplateSizeLabel: TLabel;
    TemplateSizeComboBox: TComboBox;
    GeneralizationFARLabel: TLabel;
    GeneralizationFARComboBox: TComboBox;
    GeneralizationMaxRotationLabel: TLabel;
    GeneralizationTextBox: TEdit;
    MinimalMinutiaCountTextBox: TEdit;
    UseGeneralizationOfTextBox: TEdit;
    TempaltesLabel: TLabel;
    ThresholdTextBox: TEdit;
    DegreesLabel: TLabel;
    CancelButton: TButton;
    OkButton: TButton;
    DefaultButton: TButton;
    MainPanel: TPanel;
    GeneralizationOfLabel: TLabel;
    ReturnedImageComboBox: TComboBox;
    ReturnedImageLabel: TLabel;

    procedure FormCreate(Sender: TObject);
    procedure DefaultButtonClick(Sender: TObject);
    procedure OkButtonClick(Sender: TObject);
  private
   scannerMode: TArrayOfTScannerMode;
   okPressed : boolean;
  public
    property  okPress:boolean read okPressed;
    procedure FillModes();
    property  ScannerModes: TArrayOfTScannerMode write scannerMode;
    procedure setMode(Mode: Integer);
    function  getMode(): Integer;
    procedure setTemplateSize(templateSize: TNfeTemplateSize);
    function  getTemplateSize(): TNfeTemplateSize;
    procedure setGeneralizationFAR(genFar: string);
    function  getGeneralizationFAR: string;
    procedure setReturnedImage(returnedImage: TNfeReturnedImage);
    function  getReturnedImage: TNfeReturnedImage;
  end;

implementation

{$R *.dfm}

procedure TEnrollmentOptionsFrom.FormCreate(Sender: TObject);
begin
 okPressed := false;
 GeneralizationFARComboBox.Items.Add(FloatToStr(0.1));
 GeneralizationFARComboBox.Items.Add(FloatToStr(0.01));
 GeneralizationFARComboBox.Items.Add(FloatToStr(0.001));
 //GeneralizationFARComboBox.Sorted := true;

 ReturnedImageComboBox.AddItem('None',TObject(nferiNone));
 ReturnedImageComboBox.AddItem('Binarized',TObject(nferiBinarized));
 ReturnedImageComboBox.AddItem('Skeletonized',TObject(nferiSkeletonized));

 TemplateSizeComboBox.AddItem('Small',TObject(NFETSSmall));
 TemplateSizeComboBox.AddItem('Large',TObject(NFETSLarge));
end;

procedure TEnrollmentOptionsFrom.FillModes();
 var i: Integer;
begin
 for i := 0 to Length(scannerMode) - 1 do
 begin
  ModeComboBox.AddItem(scannerMode[i].Name, TObject(scannerMode[i].Code));
 end;
 ModeComboBox.Sorted := true;
end;

procedure TEnrollmentOptionsFrom.setMode(Mode: Integer);
 var i, index: Integer;
begin
 index := 0;
 for i := 0 to ModeComboBox.Items.Count - 1 do
 begin
  if (Integer(ModeComboBox.Items.Objects[i]) = Mode) then
  begin
   index := i;
  end;
 end;
 ModeComboBox.ItemIndex := index;
end;

function TEnrollmentOptionsFrom.getMode:Integer;
begin
 Result := Integer(ModeComboBox.Items.Objects[ModeComboBox.ItemIndex]);
end;

procedure TEnrollmentOptionsFrom.setTemplateSize(templateSize: TNfeTemplateSize);
 var i, index: Integer;
begin
 index := 0;
 for i := 0 to TemplateSizeComboBox.Items.Count - 1 do
 begin
  if (TNfeTemplateSize(TemplateSizeComboBox.Items.Objects[i]) = templateSize) then
  begin
   index := i;
  end;
 end;
 TemplateSizeComboBox.ItemIndex := index;
end;

function TEnrollmentOptionsFrom.getTemplateSize: TNfeTemplateSize;
begin
 Result := TNfeTemplateSize(TemplateSizeComboBox.Items.Objects[TemplateSizeComboBox.ItemIndex]);
end;

procedure TEnrollmentOptionsFrom.setReturnedImage(returnedImage: TNfeReturnedImage);
 var i, index: Integer;
begin
 index := 0;
 for i := 0 to ReturnedImageComboBox.Items.Count - 1 do
 begin
  if (TNfeReturnedImage(ReturnedImageComboBox.Items.Objects[i]) = returnedImage) then
  begin
   index := i;
  end;
 end;
 ReturnedImageComboBox.ItemIndex := index;
end;

function TEnrollmentOptionsFrom.getReturnedImage: TNfeReturnedImage;
begin
 Result := TNfeReturnedImage(ReturnedImageComboBox.Items.Objects[ReturnedImageComboBox.ItemIndex]);
end;

procedure TEnrollmentOptionsFrom.setGeneralizationFAR(genFar: string);
begin
 if (GeneralizationFARComboBox.Items.IndexOf(genFar) = -1) then
 begin
  GeneralizationFARComboBox.Items.Add(genFar);
 end;
 GeneralizationFARComboBox.ItemIndex := GeneralizationFARComboBox.Items.IndexOf(genFar);
end;

function TEnrollmentOptionsFrom.getGeneralizationFAR: string;
begin
 Result := GeneralizationFARComboBox.Text;
end;

procedure TEnrollmentOptionsFrom.DefaultButtonClick(Sender: TObject);
begin
 SearchForDuplicatesCheckBox.Checked := true;
 MinimalMinutiaCountCheckBox.checked := true;
 MinimalMinutiaCountTextBox.Text := '10';
 setReturnedImage(nferiBinarized );
 UseGeneralizationOfTextBox.Text := '3';
 UseQualityCheckBox.Checked := true;
 ThresholdTextBox.Text := '39';
 setMode(N_MODE_GENERAL);
 setTemplateSize(nfetsLarge);
 setGeneralizationFAR('0.001');
 GeneralizationTextBox.Text := '180';
end;

procedure TEnrollmentOptionsFrom.OkButtonClick(Sender: TObject);
 var tempInteger: Integer;
     tempDouble: Double;
begin
try
 tempInteger := StrToInt(MinimalMinutiaCountTextBox.Text);
 If (tempInteger < 0) Or (255 < tempInteger) Then
 begin
  MinimalMinutiaCountTextBox.SetFocus;
  raise Exception.Create('Minimal minutia count should be in rage [0,255]');
 end;

 tempInteger := StrToInt(UseGeneralizationOfTextBox.Text);
 If (tempInteger < 3) Or (10 < tempInteger) Then
 begin
  UseGeneralizationOfTextBox.SetFocus;
  raise Exception.Create('Generalization templates count should be in rage [3,10]');
 end;

 tempInteger := StrToInt(ThresholdTextBox.Text);
 If (tempInteger < 0) Or (100 < tempInteger) Then
 begin
  ThresholdTextBox.SetFocus;
  raise Exception.Create('Threshold should be in rage [0,100]');
 end;

 tempDouble := StrToFloat(Trim(getGeneralizationFAR));
 If (tempDouble < 0) Or (100 < tempDouble) Then
 begin
  GeneralizationFARComboBox.SetFocus;
  raise Exception.Create('Generalization FAR should be in rage [0,100]');
 end;

 tempInteger := StrToInt(GeneralizationTextBox.Text);
 If (tempInteger < 0) Or (180 < tempInteger) Then
 begin
  GeneralizationTextBox.SetFocus;
  raise Exception.Create('Generalization maximal rotation should be in rage [0,180]');
 end;

 okPressed := true;
 
 self.Close;
except
 on E:Exception do
  MessageDlg('Error: ' + E.Message,
     mtError, [mbOK], 0)
 end;
end;

end.
